/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rtsgame.core.view;

import java.awt.Graphics2D;
import rtsgame.core.view.graphics.GraphicElement;

/**
 *
 * @author tom
 */
public class Sprite {
  int x = 0, y = 0;
  int prev_x = 0, prev_y = 0;

  private SpriteState state = SpriteState.eNoSelect;

  private GraphicElement graphicElement;

  public Sprite(GraphicElement graphicElement) {
    this.graphicElement = graphicElement;
  }

  public int getX() {
    return x;
  }

  public void setX(int x) {
    this.x = x;
    graphicElement.setX(x);
  }

  public int getY() {
    return y;
  }

  public void setY(int y) {
    this.y = y;
     graphicElement.setY(y);
  }

  public void moveUp( int step )
  {
    y += step;
    graphicElement.setY(y);
  }

  public void moveUp( int step, int minY )
  {
    y -= step;
    if( y < minY ) y = minY;
    graphicElement.setY(y);
  }

  public void moveDown( int step )
  {
    y += step;
    graphicElement.setY(y);
  }

  public void moveDown( int step, int maxY )
  {
    y += step;
    if( y > maxY ) y = maxY;
    graphicElement.setY(y);
  }

  public void moveRight( int step  )
  {
    x += step;
    graphicElement.setX(x);
  }

  public void moveRight( int step, int maxX )
  {
    x += step;
    if( x > maxX ) x = maxX;
    graphicElement.setX(x);
  }

  public void moveLeft( int step )
  {
    x -= step;
    graphicElement.setX(x);
  }

  public void moveLeft( int step, int minX )
  {
    x -= step;
    if( x < minX ) x = minX;
    graphicElement.setX(x);
  }


  public GraphicElement getGraphicElement() {
    return graphicElement;
  }

  public void Draw( Graphics2D graphics )
  {
    graphicElement.Draw(graphics);
    if( state == SpriteState.eSelect )
    {
      graphicElement.DrawSelect( graphics);
    }
  }

  public boolean hit( int x, int y )
  {
    return graphicElement.hit(x, y);
  }

  public boolean isCollision( Sprite sprite)
  {
    return getGraphicElement().isCollision( sprite.getGraphicElement() );
  }

  public void snapPosition()
  {
    prev_x = x;
    prev_y = y;
  }

  public void revPosition()
  {
    x = prev_x;
    y = prev_y;
  }

  public SpriteState getState() {
    return state;
  }

  public void setState(SpriteState state) {
    this.state = state;
  }



}
